require 'Common/define'
require 'Logic/Config'
require 'Common/functions'

ArenaRankItem = {};
HelperFunc.SetUIEnv(ArenaRankItem)
local this = ArenaRankItem;

this.Rank = nil;
this.txtRank = nil;
this.objRank1 = nil;
this.objRank2 = nil;
this.objRank3 = nil;
this.objHead = nil;
this.txtName = nil;
this.txtPower = nil;
this.txtScore = nil;
this.imgLevelIcon = nil;


function ArenaRankItem.Init()--todo 应该小写 暂时先大写
    local name, packageName = getUIName(PanelNames.ArenaRankItem);
    panelMgr:Push(name, packageName, this.onCreate,Config.useLocalUI);
end

function ArenaRankItem.onCreate()
    --obj:SetActive(false);
end

function ArenaRankItem.initData(obj, data)

    --data.quality = logicMgr.HeroManager.starToQuality(data.star);
    --data.state = EnumConst.HeroHeadStateEnum.NONE;

    Rank = obj:GetChild("Rank");
    txtRank = obj:GetChild("RankText");
    objRank1 = obj:GetChild("Rank1");
    objRank2 = obj:GetChild("Rank2");
    objRank3 = obj:GetChild("Rank3");

    objHead = obj:GetChild("Head"):GetChild("Head");
    txtName = obj:GetChild("Name");
    txtPower = obj:GetChild("Power");
    txtScore = obj:GetChild("Score");

    imgLevelIcon = obj:GetChild("RankIcon");

    UIComponentInterface:SetPlayerIcon(objHead,data.headId)
    txtName.text = data.name;
    txtPower.text = tostring(data.power);
    txtScore.text = tostring(data.param);

    txtRank.visible = false;
    objRank1.visible = false;
    objRank2.visible = false;
    objRank3.visible = false;
    Rank.visible = false--(data.rank == nil or data.rank <=0 or data.rank>3);

    if data.rank <= 0 then
        txtRank.visible = true;
        txtRank.text = getLanguage("NotInRank");
    else
        if data.rank == 1 then
            objRank1.visible = true;
        elseif data.rank == 2 then
            objRank2.visible = true;
        elseif data.rank == 3 then
            objRank3.visible = true;
        else
            txtRank.visible = true;
            txtRank.text = tostring(data.rank);
        end
    end

    --txtRank.visible = (data.rank == nil or data.rank <=0 or data.rank>3);
    --objRank1.visible = (tonumber(data.rank) == 1);
    --objRank2.visible = (tonumber(data.rank) == 2);
    --objRank3.visible = (tonumber(data.rank) == 3);
    local singleGradConfig = logicMgr.ArenaManager.getGradCofigByScore(data.param); --段位配置
    imgLevelIcon.url = "ui://ICONAtlas/".."rank_"..singleGradConfig.f_Id;

--[[    resMgr:LoadIconFromPrefab("ICONAtlas","rank_"..singleGradConfig.f_Id,function (sp)
        imgLevelIcon.sprite =sp;
    end);]]
end

return ArenaRankItem;
